#include <Arduino.h>

void InterruptcallBack(void);
uint8_t state = 0;

void GpioInit(void)
{
  SX1278 lora = new LoRa(GPIO_NUM_15,
                         GPIO_NUM_26,
                         GPIO_NUM_25);
  pinMode(GPIO_NUM_18, INPUT_PULLUP);
  attachInterrupt(
      digitalPinToInterrupt(GPIO_NUM_18),
      SensorCallback,
      RISING);
  lora.begin();
}

void Sysinit(void)
{
  const char *ssid = "WIFI";
  const char *password = "PASSWD";
  WiFi.begin(ssid, password);
  SX1278 lora = new LoRa(GPIO_NUM_15,
                         GPIO_NUM_26,
                         GPIO_NUM_25);
  lora.begin();
  String serverName = "http://192.168.1.101:5000/sensor";
}
String GetDataFromNode(void)
{
  String Nodedata;
  lora.receive(Nodedata);
  return Nodedata;
}
void SendDataToServer(String Nodedata)
{
  HTTPClient http;
  String serverPath = serverName + Nodedata;
  http.begin(serverPath);
  http.GET();
}

void SendAlarm(void)
{
  char alarm[] = "{\"nodeNum\":\"1000\",\
                   \"sensorState\":\"1\"}";
  lora.transmit(alarm)
}
void SendHeartbeat(void)
{
  char heart[] = "{\"nodeNum\":\"1000\",\
                   \"heartState\":\"1\"}";
  lora.transmit(heart)
}

void setup()
{
  Serial.begin(115200);
  Serial.println("start serial");
  pinMode(GPIO_NUM_18, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(GPIO_NUM_18), callBack, RISING);
  pinMode(GPIO_NUM_21, OUTPUT);
}

void loop()
{

  Serial.println("check");
  delay(500);
  if (state == 1)
  {
    Serial.println("sensor is shaking");
    digitalWrite(GPIO_NUM_21, LOW);
    delay(100);
    digitalWrite(GPIO_NUM_21, HIGH);
    state = 0;
  }
}

void SensorCallback(void)
{
  SensorCallback();
}